#include "Filter.h"
#include <iostream>

// Compile: g++ -o3 main.cpp Filter.cpp -o main.exe

int main(int argc, char *argv[])
{
	// 准备工作：读入图像
	HXLBMPFILE bmpfile, bf, result;
	int i, j;
	if (!bmpfile.LoadBMPFILE("./image/lena.bmp")) // 载入原始图像
		exit(1);								  // 不成功则退出

	img_Clone(bmpfile, bf); // 复制信息头、文件头、数据域

	addSaltNoise(bf, 3000); // 给图像添加椒盐噪声

	img_Clone(bf, result);

	int choose;

	std::cout << "Please choose the filter type:\n"
				 "1) Smoothing filtering\n"
				 "2) Sobel filtering\n"
				 "3) Median filtering\n\n";

	std::cin >> choose;

	switch (choose)
	{
	case 1:
	{
		float w[9] = {1, 1, 1, 1, 1, 1, 1, 1, 1};

		for (i = 0; i < 9; i++) // 平滑滤波应当保证w和为1。锐化则和为0
		{
			w[i] *= (float)1 / (float)9;
		}

		Spatialfilter(bf, w, 3, 3);
		break;
	}

	case 2:
	{
		float w[9] = {1, 2, 1, 0, 0, 0, -1, -2, -1}; // Sobel水平模板

		Spatialfilter(bmpfile, bf, w, 3, 3);
		break;
	}

	case 3:
	default:
	{
		float w[9] = {1, 1, 1, 1, 3, 1, 1, 1, 1}; // 出现次数w

		Medianfilter(bf, result, w, 3, 3);
		break;
	}
	}

	std::cout << "Done!\n";

	return 0;
}